package rpc.client.netty;


import lombok.extern.slf4j.Slf4j;
import rpc.client.RpcClientProxy;
import rpc.common.extension.ExtensionLoader;
import rpc.entity.HelloObject;
import rpc.intf.RpcClient;
import rpc.intf.LoadBalancer;
import rpc.services.ByeService;
import rpc.services.HelloService;

@Slf4j
public class TestNettyClient {
    public static void main(String[] args) {
        //负载均衡算法
        LoadBalancer loadBalancer = ExtensionLoader
                .getExtensionLoader(LoadBalancer.class)
                .getExtension("rrlb");
        //创建客户端
        RpcClient rpcClient = new NettyClient(loadBalancer);
        //动态代理
        RpcClientProxy rpcClientProxy = new RpcClientProxy(rpcClient);

        HelloService helloService = rpcClientProxy.getProxy(HelloService.class);

        Object res = helloService.hello(new HelloObject(12, "This is a message"));
        log.debug("方法返回结果: {}", res);

        ByeService byeService = rpcClientProxy.getProxy(ByeService.class);
        res = byeService.bye("Server");
        log.debug("方法返回结果: {}", res);
    }
}
